
package com.xiashitech.agent.constants;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;

import java.util.HashMap;
import java.util.Map;


public enum ApiParamDataType {

    STRING("String"),
    INTEGER("Integer"),
    INT("int"),
    BYTE("Byte"),
    BYTE_("byte"),
    SHORT("Short"),
    SHORT_("short"),
    LONG("Long"),
    LONG_("long"),
    FLOAT("Float"),
    FLOAT_("float"),
    DOUBLE("Double"),
    DOUBLE_("double"),
    BIG_DECIMAL("BigDecimal",Boolean.TRUE),
    CHARACTER("Character"),
    CHAR("char"),
    BOOLEAN("Boolean"),
    BOOLEAN_("boolean"),
    DATE("Date",Boolean.TRUE),
    TIME("Time",Boolean.TRUE),
    TIMESTAMP("Timestamp",Boolean.TRUE),
    BYTE__("byte[]"),
    CLOB("Clob",Boolean.TRUE),
    BLOB("Blob",Boolean.TRUE),
    VARBINARY("VARBINARY",Boolean.TRUE),
    ARRAY("ARRAY"),
    BLOB_("BLOB",Boolean.TRUE),
    JSON("Json"),
    JSON_OBJECT("JsonObject"),
    JSON_ARRAY("JsonArray"),
    OBJECT("Object"),
    MAP("Map"),
    LIST("List"),
    SET("Set"),
    ARRAY_LIST("ArrayList"),
    HASH_MAP("HashMap"),
    HASH_SET("HashSet");
    private final String value;
    private final Boolean analogyPrimitive;
    private final static Map<String, ApiParamDataType> CONSTANTS = new HashMap<String, ApiParamDataType>();

    static {
        for (ApiParamDataType c: values()) {
            CONSTANTS.put(c.value, c);
        }
    }

    ApiParamDataType(String value) {
        this.value = value;
        this.analogyPrimitive = Boolean.FALSE;
    }

    ApiParamDataType(String value, Boolean analogyPrimitive) {
        this.value = value;
        if(analogyPrimitive != null) {
            this.analogyPrimitive = analogyPrimitive;
        } else {
            this.analogyPrimitive = Boolean.FALSE;
        }
    }

    @Override
    public String toString() {
        return this.value;
    }

    @JsonValue
    public String value() {
        return this.value;
    }

    @JsonCreator
    public static String fromValue(String value) {
        ApiParamDataType constant = CONSTANTS.get(value);
        if (constant != null) {
            return constant.value();
        } else {
            return STRING.value();
        }
    }

    public static Boolean judgeAnalogyPrimitive(String value) {
        ApiParamDataType constant = CONSTANTS.get(value);
        if(constant != null) {
            return constant.analogyPrimitive;
        } else {
            return Boolean.FALSE;
        }
    }

}
